package cn.imvc.util;

import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import com.aliyun.opensearch.*;
import com.aliyun.opensearch.object.KeyTypeEnum;

public class GoodsSearch {
    private String host;
    private String accesskey;
    private String secret;
    private String index;

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getAccesskey() {
        return accesskey;
    }

    public void setAccesskey(String accesskey) {
        this.accesskey = accesskey;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }
    
    public String getIndex() {
		return index;
	}

	public void setIndex(String index) {
		this.index = index;
	}


	private CloudsearchClient client;

    public CloudsearchSearch getSearch() throws UnknownHostException {
        if(client==null){
            Map<String, Object> opts = new HashMap<String, Object>();
            client = new CloudsearchClient(getAccesskey(), getSecret() , getHost(), opts, KeyTypeEnum.ALIYUN);
        }
        CloudsearchSearch search = new CloudsearchSearch(client);
        search.addIndex(getIndex());
        search.setFormat("json");
        return search;
    }
    
    public CloudsearchSearch getGoodsOrder() throws UnknownHostException {
        if(client==null){
            Map<String, Object> opts = new HashMap<String, Object>();
            client = new CloudsearchClient(getAccesskey(), getSecret() , getHost(), opts, KeyTypeEnum.ALIYUN);
        }
        CloudsearchSearch search = new CloudsearchSearch(client);
        search.addIndex("goods_order");
        search.setFormat("json");
        return search;
    }
}
